Skip to content

Add Google Cloud Platform Labels Support #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2018

Conversation

jbutz
Copy link
Contributor

@jbutz jbutz commented Jan 25, 2018

What did you implement:

Closes #94

How did you implement it:

I added a new property to the properties object on the function template, when compiling the functions. The resulting value, an object, is the result of merging a labels property on the provider object and a labels property on the function object. The function object's labels object takes priority, overriding properties on the provider objects's labels.

If no labels properties are defined the result is an empty object.

How can we verify it:

Use the following serverless.yml file in association with the google-nodejs template, changing the credentials and project values as necessary.

service: gcf-nodejs

provider:
  name: google
  runtime: nodejs
  project: my-project
  credentials: ~/.gcloud/keyfile.json
  labels:
    app: google-nodejs-example
    test: provider-label
    

plugins:
  - serverless-google-cloudfunctions

package:
  exclude:
    - node_modules/**
    - .gitignore
    - .git/**

functions:
  first:
    handler: http
    events:
      - http: path
    labels:
      test: function-label

Deploy the function then login the Google Cloud Platform console and go to the Functions section. Select the function you just deployed. On the right the pane should show an app label with the value google-nodejs-example and a test label with the value function-label

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@jbutz
Copy link
Contributor Author

jbutz commented Jan 25, 2018

I intend to update the documentation in the main repo next, but that can't really be deployed until this is released.

Copy link

@adnasa adnasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
let's hope you get yourself a merge soon 😉

funcTemplate.properties.labels = _.assign({},
_.get(this, 'serverless.service.provider.labels') || {},
_.get(funcObject, 'labels') || {},
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this makes much more sense now after your comment in #94

Copy link

@adnasa adnasa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
let's hope you get yourself a merge soon 😉

@jbutz
Copy link
Contributor Author

jbutz commented Jan 30, 2018

I have created a PR on the main serverless repo for the documentation

@jbutz
Copy link
Contributor Author

jbutz commented Feb 16, 2018

@pmuens are you able to review this?

Copy link
Contributor

@pmuens pmuens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! That looks good from a code perspective 👍

Thanks for adding this @jbutz and thanks for reviewing @adnasa 👍

@pmuens pmuens merged commit d166e46 into serverless:master Mar 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants